from datetime import datetime

from sqlalchemy import Column, Integer, String, CHAR, DECIMAL

from models.base import Base


class report_source_info(Base):
    __tablename__ = 'report_source_info'
    id = Column(Integer, primary_key=True, autoincrement=True)
    order_number = Column(String(80), default='')
    create_time = Column(Integer, default=0)
    source_type = Column(String(30), default='local')
    source = Column(String(1000), default='')
    rate = Column(DECIMAL(5, 2), default=0)

    def __init__(self, ):
        self.create_time = int(datetime.now().timestamp())

    @property
    def create_datetime(self):
        if self.create_time:
            return datetime.utcfromtimestamp(self.create_time + 28800).strftime("%Y-%m-%d %H:%M:%S")
        else:
            return None
